package com.zhb.lkd.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collections;
import java.util.List;

/**
 * 分页结果包装
 */
@ApiModel(value = "分页数据消息体", description = "分页数据统一对象")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResponse<T> {

    @ApiModelProperty(value = "页码", required = true)
    private Integer pageIndex;
    @ApiModelProperty(value = "页尺寸", required = true)
    private Integer pageSize;
    @ApiModelProperty(value = "总条目数", required = true)
    private Long totalPage;
    @ApiModelProperty(value = "总页数", required = true)
    private long totalCount;
    @ApiModelProperty(value = "数据列表", required = true)
    private List<T> currentPageRecords;
    /**
     * 返回分页对象
     *
     * @param page mp的page对象
     */
    public PageResponse(Page page) {
        this.pageIndex = (int)page.getCurrent();
        this.pageSize = (int)page.getSize();
        this.totalPage = page.getPages();
        this.totalCount = page.getTotal();
        this.currentPageRecords = page.getRecords();
    }

    /**
     * 返回分页对象
     *
     * @param page mp的page对象
     * @param list 当前页数据集合
     */
    public PageResponse(Page page, List<T> list) {
        this.pageIndex = (int)page.getCurrent();
        this.pageSize = (int)page.getSize();
        this.totalPage = page.getPages();
        this.totalCount = page.getTotal();
        this.currentPageRecords = list;
    }
}